using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.SkillSet
{
    public class SkillSetItemsInsertDataSource : NonQuerySource<BusinessObjects.SkillSet>
    {
        public override bool Execute(BusinessObjects.SkillSet request)
        {
            const string skillSetItemsInsert = "dbo.training_api_SkillSetItemInsert";
            return
                SqlHelper.ExecuteBulkNonQuery(
                    ConnectionStrings.TrainingDb,
                    CommandType.StoredProcedure,
                    skillSetItemsInsert,
                    request.SkillSetItems,
                    skill => 
                        {
                            var parameters = new SqlParameter[3];
                            parameters[0] = new SqlParameter("@SkillID", SqlDbType.Int){ Value = skill.SkillId};
                            parameters[1] = new SqlParameter("@SkillSetID", SqlDbType.Int){ Value = request.SkillSetId};
                            parameters[2] = new SqlParameter("@RetrainFreq", SqlDbType.Int) {Value = skill.RetrainFreq};
                            return parameters; 
                        });
        }
    }
}